#!/usr/bin/python3

import cv2
import numpy as np


def print_im(name, var, num_of_col, rs):
    print("###" * 20, name, "###" * 20)
    for ii in range(rs):
        for jj in range(num_of_col):
            print(var[ii, jj], end=" ")
            jj += 1
        ii += 1
        print()
    print()


image = cv2.imread('/Users/ben/Downloads/Lena.jpg')
cv2.namedWindow("source:")
cv2.imshow("Source:", image)

(B, G, R) = cv2.split(image)

image_gauss = cv2.GaussianBlur(image, (5, 5), 0)
cv2.imshow("GaussianBlur:", image_gauss)

rows, cols = image.shape[:2]  # height, width

image_resize = cv2.resize(image, (int(cols/2), int(rows/2)))   # resize dsize (width, height)
cv2.imshow("resize:", image_resize)

image_pyrDown = cv2.pyrDown(image)
cv2.imshow("pyrDown:", image_pyrDown)

image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow("Gray:", image_gray)

ret, image_threshold = cv2.threshold(image_gray, 120, 0xff, cv2.THRESH_BINARY)
cv2.imshow("THRESHOLD:", image_threshold)

image_hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
(H, S, V) = cv2.split(image_hsv)

cv2.imshow("B:", B)
cv2.imshow("G:", G)
cv2.imshow("R:", R)
cv2.imshow("H:", H)
cv2.imshow("S:", S)
cv2.imshow("V:", V)

print('######'*20, '\n', image.shape, cols, rows, '\n')

tmp = 10  # only print limited rows
print_im("BGR", image, cols, tmp)
print_im("B", B, cols, tmp)
print_im("G", G, cols, tmp)
print_im("R", R, cols, tmp)
print_im("H", H, cols, tmp)
print_im("S", S, cols, tmp)
print_im("V", V, cols, tmp)

zeros = np.zeros(image.shape[:2], dtype="uint8")
cv2.imshow("BlueMergeZero", cv2.merge([B, zeros, zeros]))
cv2.imshow("GreenMergeZero", cv2.merge([zeros, G, zeros]))
cv2.imshow("RedMergeZero", cv2.merge([zeros, zeros, R]))

cv2.waitKey(0)
cv2.destroyAllWindows()
